﻿using ServerBase.Config;
using SvGame.Objects;

namespace SvGame.Logic;

public static partial class GameLogic
{
    public static int GetProp(this IRole me, EPropType prop)
    {
        int value = prop switch
        {
            EPropType.Kee => me.StatusCur.Kee,
            EPropType.Sen => me.StatusCur.Sen,
            EPropType.Force => me.StatusCur.Force,
            EPropType.Mana => me.StatusCur.Mana,
            EPropType.Food => me.StatusCur.Food,
            EPropType.Water => me.StatusCur.Water,

            EPropType.EffKee => me.StatusEff.Kee,
            EPropType.EffSen => me.StatusEff.Sen,

            EPropType.MaxKee => me.StatusMax.Kee,
            EPropType.MaxSen => me.StatusMax.Sen,
            EPropType.MaxForce => me.StatusMax.Force,
            EPropType.MaxMana => me.StatusMax.Mana,
            EPropType.MaxFood => me.StatusMax.Food,
            EPropType.MaxWater => me.StatusMax.Water,
            _ => 0,
        };
        return value;
    }
    public static string GetPropName(this EPropType prop)
    {
        string value = prop switch
        {
            EPropType.Kee => "气血",
            EPropType.Sen => "精神",
            EPropType.Force => "内力",
            EPropType.Mana => "法力",
            EPropType.Food => "食物",
            EPropType.Water => "饮水",

            EPropType.EffKee => "有效气血",
            EPropType.EffSen => "有效精神",

            EPropType.MaxKee => "最大气血",
            EPropType.MaxSen => "最大精神",
            EPropType.MaxForce => "最大内力",
            EPropType.MaxMana => "最大法力",
            EPropType.MaxFood => "最大食物",
            EPropType.MaxWater => "最大饮水",
            _ => "属性",
        };
        return value;
    }
    public static int GetProp(this IRole me, EProp prop)
    {
        var value = me.Comb.PropsEquip.Get(prop);
        value += me.Comb.PropsBuff.Get(prop);
        return value;
    }
    public static int UseProp(this IRole me, EPropType prop, int value)
    {
        switch (prop)
        {
            case EPropType.Kee:
                me.StatusCur.Kee -= value;
                return me.StatusCur.Kee;
            case EPropType.Sen:
                me.StatusCur.Sen -= value;
                return me.StatusCur.Sen;
            case EPropType.Force:
                me.StatusCur.Force -= value;
                return me.StatusCur.Force;
            case EPropType.Mana:
                me.StatusCur.Mana -= value;
                return me.StatusCur.Mana;
            case EPropType.Food:
                me.StatusCur.Food -= value;
                return me.StatusCur.Food;
            case EPropType.Water:
                me.StatusCur.Water -= value;
                return me.StatusCur.Water;
            default:
                break;
        }
        
        return value;
    }

    public static void PropsEquipSet(this IRole me)
    {
        me.Comb.PropsEquip.Clear();
        foreach (var kvp in me.DictWear)
        {
            if (me.DictEquip.TryGetValue(kvp.Value, out var equip))
            {
                me.Comb.PropsEquip.Add(EProp.damage, equip.Cfg.Damage);
                me.Comb.PropsEquip.Add(EProp.armor, equip.Cfg.Armor);
            }
        }
    }
    
    public static RoleInfoProps InfoProps(this IRole me)
    {
        var info = new RoleInfoProps();
        info.Damage = me.GetProp(EProp.damage);
        info.Armor = me.GetProp(EProp.armor);
        info.Dodge = me.GetProp(EProp.dodge);
        info.Parry = me.GetProp(EProp.parry);
        return info;
    }
}
